import './logger.js';

// import http from 'http';
import fetch from 'node-fetch';
import fs from 'node:fs';
import os from 'os-utils';

export const readFile = async (url) => {
    return new Promise((resolve, reject) => {
        fetch(url)
            .then((response) => response.text())
            .then((data) => resolve(data))
            .catch((error) => reject(error));
    });
};

export const checkFileExists = (folderPath, fileName) => {
    try {
        const files = fs.readdirSync(folderPath);
        // console.log(files, fileName)
        return files.includes(fileName);
    } catch (error) {
        console.error('读取文件夹失败：', error);
        return false;
    }
};

export const cpuUsage = () => {
    return new Promise((resolve, reject) => {
        os.cpuUsage(function (v) {
            resolve(10);
        });
    });
};
export const mem = () => {
    return 10;
};
